﻿using ReflectionStudio.Core.Events;
using System;
using System.ComponentModel;
using System.Data;
using System.Windows;
namespace WPFExcelReport
{
    public partial class TAM06
    { 
        public TAM06()
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            MV = new VAMEINST();
            this.DataContext = MV;
            InitializeComponent();
        }
        public override void vwMaster_CurrentChanged(object sender, EventArgs e)
        {
            base.vwMaster_CurrentChanged(sender, e);
        }

        public override void OnSave()
        {
            if (!IsSaved)
                return;
            if (dwMaster == null)
                return;
            TMV.UpdateAMEINST(dwMaster, 0);
            string key = KEY;
            KEY = "";
            KEY = key;
            base.OnSave();
        }

        public override void LOADBYAUF()
        {
            TBMain.Clear();
            if (ORDERNUM.Length < 14)
                return;
            dwData = TMV.TBMain.NewRow();
            //+ " WHERE AMEMANDANT=:AMEMANDANT: AND AMENRKRS=:AMENRKRS: AND AMELFDNR=:AMELFDNR: AND AMEPOS=:AMEPOS: AND AMEMODNR=:AMEMODNR: AND AMEEINSTNR=:AMEEINSTNR: ";
            dwData["AMEMANDANT"] = app.Mandant;
            dwData["AMENRKRS"] = "AND AMENRKRS= '" + ORDERNUM.Substring(0, 2) + "'";
            dwData["AMELFDNR"] = "AND AMELFDNR= '" + ORDERNUM.Substring(2, 4) + "'";
            dwData["AMEPOS"] = "AND AMEPOS= '" + ORDERNUM.Substring(6, 2) + "'";
            dwData["AMEMODNR"] = "AND AMEMODNR= '" + ORDERNUM.Substring(8, 3) + "'";
            dwData["AMEEINSTNR"] = "AND AMEEINSTNR= '" + ORDERNUM.Substring(11, 3) + "'";
            SResult = TMV.QAME02(dwData);
            MergeData(SResult, true);
            base.LOADBYAUF();
        }
        public override void OnBDEKENChg()
        {
            if (!IsEdit)
                return;
            if (dwMaster == null)
                return;
            TMV.AMEBDEKEN =Helpers.Helper.Left(BDEKEN.Trim().PadRight(8),8);
            base.OnBDEKENChg();
        }
    }
}
